package com.springboot.uav.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Created by IntelliJ IDEA.
 * &#064;Author : Zys
 * &#064;create 2024/11/13 13:04
 */
@Configuration
public class CorsConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("http://localhost:5173")  // 明确允许的前端地址
                .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")  // 允许的方法
                .allowedHeaders("Content-Type", "Authorization", "*")  // 允许的请求头
                .exposedHeaders("Authorization", "*")  // 允许暴露的响应头
                .allowCredentials(true);  // 允许携带凭证
    }
}
